import typescript from '@rollup/plugin-typescript'
import copy from 'rollup-plugin-copy'
import json from '@rollup/plugin-json'

const outputDir = 'dist'

console.log('on build...')

export default {
  output: {
    dir: outputDir,
    format: 'cjs',
    preserveModules: true,
  },
  external: ['@vue/cli-service', '@vue/cli-plugin-typescript', 'tapable', 'mustache', 'lodash', 'mkdirp'],
  plugins: [
    typescript({
      target: 'es2020',
    }),
    copy({
      targets: [
        ['./**/*.tpl', '!./node_modules/**'],
        './zcat/sourcemap.js',
        './template/**/*.(vue|ts|js|png|scss|tpl)',
        './plugins/docs/site/*',
        './plugins/docs/commader/md-loader/*',
        './template/visual-report/index.html',
        './template/visual-report/assets/*',
      ].map((a) => ({
        src: a,
        dest: outputDir,
        rename: (name, extension, fullPath) => {
          return fullPath
        },
      })),
      flatten: true,
    }),
    json(),
  ],
}
